// pages/index/health_report/health_report.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    healthScore: '0分',
    currentWeight: '0KG',
    bmi: '0',
    bfr: '0.00%',
    health_status: '偏瘦',
    testButton:[{
      url: '../test_list/test_list'
    }]
  },
  onLoad: function (options) {
    let healthy_report_source = wx.getStorageSync('healthy_report_source')
    if (healthy_report_source) {
      let bmi = healthy_report_source.weight / (healthy_report_source.height * healthy_report_source.height)
      let standard_weight = healthy_report_source.sex ? ((healthy_report_source.height * 100- 80) * 0.7) : ((healthy_report_source.height * 100 - 70) * 0.6)

      let health_status = '正常'
      if (bmi > 24) health_status = '偏重'
      if (bmi < 18) health_status = '偏瘦'
      
      this.setData({
        healthScore: Math.ceil((1 - ((Math.abs(healthy_report_source.weight - standard_weight)) / standard_weight)) * 100) + '分',
        currentWeight: healthy_report_source.weight + 'KG',
        bmi: bmi.toFixed(2),
        bfr: (1.2 * bmi + 0.23 * healthy_report_source.age - 5.4 - 10.8 * healthy_report_source.sex).toFixed(2) + '%',
        healthStatus: health_status
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '请先填写必要的评测数据！',
        showCancel: false,
        confirmText: '确定',
        success: function () {
          wx.navigateTo({
            url: '../test_list/test_list'
          })
        }
      })
    }
  }
})